package com.yeyaomai.dksns.flowis.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import com.yeyaomai.dksns.flowis.dao.ReferPageDao;
import com.yeyaomai.dksns.flowis.domain.ReferPage;
import com.yeyaomai.dksns.flowis.page.PageImplResult;
import com.yeyaomai.dksns.flowis.page.PageRequestOrder;
import com.yeyaomai.dksns.flowis.page.SplitConstant;
import com.yeyaomai.dksns.flowis.service.ReferPageService;

@Service
public class ReferPageServiceImpl implements ReferPageService {

	@Resource
	private ReferPageDao referPageDao;

	@Override
	public void addReferPage(ReferPage referPage) {
		referPageDao.addReferPage(referPage);

	}

	@Override
	public ReferPage getReferPageById(long id) {
		return referPageDao.getReferPageById(id);
	}

	@Override
	public List<ReferPage> getReferPageByDay(Map<String, Object> map) {
		return referPageDao.getReferPageByDay(map);
	}

	@Override
	public Page<ReferPage> getDataPage(Map<String, Object> map,
			Integer currentpage) {
		long domainCount = referPageDao.getReferPageCount(map.get("fromReferDay").toString(),map.get("toReferDay").toString());
		PageRequestOrder request = new PageRequestOrder(currentpage, SplitConstant.PAGE_SIZE);
		List<ReferPage> pageList = new ArrayList<ReferPage>();
		map.put("startNumber", request.start());
		map.put("endNumber", request.end());
		pageList = referPageDao.getReferPageByDay(map);
		Page<ReferPage> result = new PageImplResult<ReferPage>(pageList, request, domainCount);
		return result;
	}

}
